// pages/corporate-certification-detail/corporate-certification-detail.js
import { Company } from '../../../models/company'
const companyModel = new Company()
import UploadImg from '../../../util/uploadImg'
const uploadImg = new UploadImg()
import {check} from '../../../util/identityCheck'

Page({
  data: {
    publishText: '立即认证',
    auditState: 0,
    companyInfo: {
      companyName: '',
      companyDesc: '',
      contact: '',
      phone: '',
      licensePic: './images/example.png',
      infoPic: []
    }
  },

  onLoad (){
    if(!check())return
  },
  onShow () {
    this.getCompanyInfo()
  },

  getCompanyInfo () {
    companyModel.info(res => {
      this.setData({
        auditState: res.auditState
      })
      if (res.infoPic) {
        res.infoPic = res.infoPic.split(',')
      }
      this.setData({
        'companyInfo': res
      })
    })
  },

  inputChange (event) {
    let key = `companyInfo.${event.currentTarget.dataset.type}`
    this.setData({
      [key]: event.detail
    })
  },

  previewImg (event) {
    let urls = event.currentTarget.dataset.urls
    wx.previewImage({
      urls: urls
    })
  },

  toNewPage (event) {
    let path = event.currentTarget.dataset.path
    wx.navigateTo({
      url: `/pages/${path}/${path}`
    })
  }
})
